package utils;

import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.xpath.XPath;
import javax.xml.xpath.XPathFactory;

import org.w3c.dom.Document;

public class CurrencyUtils {
	
	private Double newestValue;

	public void updateOnlineCurrency() throws Exception {
		Document doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse("http://www.vietcombank.com.vn/ExchangeRates/ExrateXML.aspx");
		XPathFactory xpfactory = XPathFactory.newInstance();
		XPath path = xpfactory.newXPath();
		
		String vnd = path.evaluate("/ExrateList/Exrate[@CurrencyCode='USD']/@Sell", doc);
		newestValue = Double.valueOf(vnd);
	}
	
	public Double getNewestValue() {
		return newestValue;
	}
}